package com.learner.common.exception;

import lombok.Data;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* @author ice2020x
* @Date: 2023/3/8
* @Description: 
**/
@RestControllerAdvice
@Data
@Order(Ordered.LOWEST_PRECEDENCE)
public class RestExceptionHandler {


    /**
     * BaseRuntimeException 异常装换
     * @param exception
     * @return
     */
    @ExceptionHandler(BaseRuntimeException.class)
    public RestException handleException(BaseRuntimeException exception) {
        RestException restException = new RestException(exception.getCode(), exception.getMsg(),exception);
        return CommonExceptionUtil.process(restException);
    }

    /**
     * 全局异常处理
     *
     * @param exception
     * @return
     */
    @ExceptionHandler(Exception.class)
    public RestException handleException(Exception exception) {
        return CommonExceptionUtil.process(exception);
    }

}
